package ynu.edu.online_course.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ynu.edu.online_course.entity.Chapter;
import ynu.edu.online_course.mapper.ChapterMapper;
import ynu.edu.online_course.service.ChapterService;

import java.util.List;

@Service
public class ChapterServiceImpl implements ChapterService {

    @Autowired
    private ChapterMapper chapterMapper;

    @Override
    public List<Chapter> getChaptersByCourseId(Long courseId) {
        return chapterMapper.findByCourseId(courseId);
    }

    @Override
    public void addChapter(Chapter chapter) {
        chapterMapper.insertChapter(chapter);
    }

    @Override
    public void updateChapter(Chapter chapter) {
        chapterMapper.updateChapter(chapter);
    }

    @Override
    public List<Chapter> getSubChapters(Long parentId) {
        return chapterMapper.findSubChapters(parentId);
    }
}